var UserListController = BaseController.extend({
	_userModel : null,
	_dataTable : null,

	init : function($scope, userModel) {
		this._userModel = userModel;
		this._super($scope)
	},

	defineScope : function() {
		this.$scope.userTable = new DataTable([ {
			field : 'username',
			displayName : '用户名',
			sortable : false,
			show : true
		}, {
			field : 'fullname',
			displayName : '姓名',
			sortable : false,
			show : true
		}, {
			field : 'email',
			displayName : '邮箱',
			sortable : false,
			show : true
		}, {
			field : 'roles',
			displayName : '角色',
			sortable : false,
			show : true
		}, {
			field : 'enablement',
			displayName : '状态',
			sortable : false,
			show : true
		} ]);

		this._userModel.get(function(data, status, headers, config) {
			var users = new Array();
			for ( var key in data) {
				var userInfo = data[key];
				if (userInfo.enablement == true) {
					userInfo.enablement = '激活';
				} else {
					userInfo.enablement = '未激活';
				}
				
				var rolesMap = {'BASIC' : '用户', 'ADMIN' : '管理员'};
				
				var roleString = '';
				if (userInfo.roles == null || userInfo.roles == "") {
					userInfo.roles = '';
				} else {
					for(var i = 0; i< userInfo.roles.length; i++) {
						if(i != 0) {
							roleString += '; '
						}
						roleString += rolesMap[userInfo.roles[i]];
					}
					
					userInfo.roles = roleString;
				} 
				users[key] = userInfo;
			}
			this.$scope.userTable.data = users;
		}.bind(this));
	}
})

UserListController.$inject = [ '$scope', 'UserModel' ];